package batch.common.code;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;

import batch.common.db.ConnectionManager;

public class CodeManager {
	private String LANG_DELIM = ";";

	private String DELIM = "|";

	public String[] getLangs(String site_code) {
		
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;

		String[] tokens = null;

		StringBuffer sQuery = new StringBuffer()
				.append("	SELECT descr FROM  G_CO_CODE  ")
				.append("   WHERE b_code = '06' AND s_code <> '000' AND name = '"+ site_code.toLowerCase() + "'");
		
		try {
			conn = ConnectionManager.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sQuery.toString());
			while (rs.next()) {
				String strDescr = rs.getString(1);
				StringTokenizer token = new StringTokenizer(strDescr, LANG_DELIM);
				tokens = new String[token.countTokens()];
				int i = 0;
				while (token.hasMoreElements()) {
					String tmp = (String) token.nextElement();
					tokens[i++] = tmp.substring(0, tmp.indexOf(DELIM));
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (rs != null)
				try {
					rs.close();
				} catch (Exception se) {
				}
			if (stmt != null)
				try {
					stmt.close();
				} catch (Exception se) {
				}
			if (conn != null)
				try {
					conn.close();
				} catch (Exception se) {
				}
		}
		return tokens;
	}
}
